package com.ganbo.msd.user.controller;

import com.ganbo.msd.user.api.clients.UserClient;
import com.ganbo.msd.user.api.entity.User;
import com.ganbo.msd.user.config.UserConfig;
import com.ganbo.msd.user.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RefreshScope
@RequestMapping("/feign/user")
public class UserController implements UserClient {

    @Value("${server.port}")
    private Integer port;

    @Value("${pattern.dateformat}")
    private String dateformat;

    @Autowired
    private UserConfig userConfig;


    @Autowired
    private UserService userService;

    /**
     * 路径： /user/110
     *
     * @param id 用户id
     * @return 用户
     */
    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id, @RequestHeader(value = "Truth", required = false) String truth) {
        System.out.println("truth: " + truth);
        User user = userService.queryById(id);
        user.setPort(port);
        System.out.println("dateformat=====>" + dateformat);
        log.info("userConfig====>" + userConfig);
        return user;
    }

    @Override
    public User findById(Long id) {
        User user = userService.queryById(id);
        return user;
    }
}
